﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace WebSite_CodeMan.BaseClass
{
    public class HtmlCommon
    {
        /// <summary>
        /// 获取模板所在文件夹
        /// </summary>
        /// <returns></returns>
        private static string GetSkinPath()
        {
            string SKinPath = (string.IsNullOrEmpty(Common.GetMes.GetCookies("SKIN"))) ? BLL.WebInfo.GetWebTemplateInfo() : Common.GetMes.GetCookies("SKIN");
            Common.SetMes.CreatCookies("SKIN", 1, SKinPath, "");
            return SKinPath;
        }
        /// <summary>
        /// 载入模板文件
        /// </summary>
        /// <param name="strType"></param>
        /// <returns></returns>
        public static StringBuilder GetBaseHtmlNote(string strType, string strValue, System.Web.UI.Page rPage)
        {
            string SKinPath = GetSkinPath();
            StringBuilder strHtml = new StringBuilder();
            switch (strType)
            {
                case "list":
                    string ListFile = "List.html";
                    ListFile = BLL.NoteInfo.GetClassTempleate(strValue, "T_ListTemplete");
                    strHtml.Append(Common.FileComm.ReadFiles(rPage.Server.MapPath("~/Template/") + SKinPath + "/" + ListFile));
                    break;
                case "note":
                    string NoteFile = "Note.html";
                    ListFile = BLL.NoteInfo.GetClassTempleate(strValue, "T_NoteTemplete");
                    strHtml.Append(Common.FileComm.ReadFiles(rPage.Server.MapPath("~/Template/") + SKinPath + "/" + NoteFile));
                    break;
                case "head":
                    strHtml.Append(Common.FileComm.ReadFiles(rPage.Server.MapPath("~/Template/") + SKinPath + "/Head.html"));
                    break;
                case "foot":
                    strHtml.Append(Common.FileComm.ReadFiles(rPage.Server.MapPath("~/Template/") + SKinPath + "/Foot.html"));
                    break;
                case "about":
                    strHtml.Append(Common.FileComm.ReadFiles(rPage.Server.MapPath("~/Template/") + SKinPath + "/About.html"));
                    break;
                case "sitemap":
                    strHtml.Append(Common.FileComm.ReadFiles(rPage.Server.MapPath("~/Template/") + SKinPath + "/sitemap.html"));
                    break;
                default:
                    strHtml.Append(Common.FileComm.ReadFiles(rPage.Server.MapPath("~/Template/") + SKinPath + "/Index.html"));
                    break;
            }
            strHtml.Replace("\r\n","");
            return strHtml;
        }
        /// <summary>
        /// 替换页面头部信息
        /// </summary>
        /// <param name="rPage"></param>
        /// <param name="nowClassID"></param>
        /// <param name="strType"></param>
        /// <returns></returns>
        public static StringBuilder HtmlReplaceWebMes(StringBuilder strHtml, string nowClassID, string strType)
        {
            OleDbDataReader DataRead = BLL.WebInfo.GetWebBaseInfo("4");
            if (string.IsNullOrEmpty(nowClassID))
            {
                if (DataRead.HasRows)
                {
                    DataRead.Read();
                    strHtml.Replace("{#WebTitle}", DataRead["T_WebName"].ToString());
                    strHtml.Replace("{#KeyWords}", DataRead["T_WebKey"].ToString());
                    strHtml.Replace("{#Description}", Common.GetMes.GetFirstString(DataRead["T_WebDes"].ToString(),80));
                    strHtml.Replace("{#Skin}", "Css_Style/" + DataRead["T_WebSkin"].ToString());
                }
                DataRead.Close();
                DataRead.Dispose();
            }
            else
            {
                if (DataRead.HasRows)
                {
                    DataRead.Read();
                    strHtml.Replace("{#Skin}", "../Css_Style/" + DataRead["T_WebSkin"].ToString());
                    strHtml.Replace("{#WebTitle}", "{#WebTitle}_" + DataRead["T_WebName"].ToString());
                }
                DataRead.Close();
                DataRead.Dispose();

                DataRead = (strType == "list") ? BLL.NoteInfo.GetNoteClassMes(nowClassID) : BLL.NoteInfo.GetAllNoteInfoMes(nowClassID);
                if (DataRead.HasRows)
                {
                    DataRead.Read();
                    if (strType == "list")
                    {
                        strHtml.Replace("{#WebTitle}", DataRead["T_ClassName"].ToString() + "_" + DataRead["T_ClassEnName"].ToString());
                        strHtml.Replace("{#KeyWords}", DataRead["T_ClassKey"].ToString());
                        strHtml.Replace("{#Description}", DataRead["T_ClassDes"].ToString());
                        strHtml.Replace("{#WebMenuMes}", "<a href=\"../Index.html\" title=\"首页\">首页</a> ＞ " + DataRead["T_ClassName"].ToString());
                    }
                    else
                    {
                        strHtml.Replace("{#WebTitle}", DataRead["T_NoteTitle"].ToString());
                        strHtml.Replace("{#KeyWords}", DataRead["T_NoteKey"].ToString());
                        strHtml.Replace("{#Description}", DataRead["T_NoteDes"].ToString());
                        strHtml.Replace("{#WebMenuMes}", "<a href=\"../Index.html\" title=\"首页\">首页</a> ＞ <a href=\"../" + DataRead["T_ClassEnName"].ToString() + "/Index.html\" title=\"" + DataRead["T_ClassName"].ToString() + "\">" + DataRead["T_ClassName"].ToString() + "</a> ＞ " + DataRead["T_NoteTitle"].ToString());
                    }
                }
                DataRead.Close();
                DataRead.Dispose();
            }
            return strHtml;

        }
        /// <summary>
        /// 替换生成页面头部
        /// </summary>
        /// <param name="strKey"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public static StringBuilder HtmlReplaceHead(System.Web.UI.Page rPage, string nowClassID)
        {
            StringBuilder strHtml = GetBaseHtmlNote("head", "", rPage);
            OleDbDataReader DataRead = BLL.WebInfo.GetWebBaseInfo("1");
            if (DataRead.HasRows)
            {
                DataRead.Read();
                strHtml.Replace("{#WebTopTitle}", DataRead["T_WebWord"].ToString());
                strHtml.Replace("{#WebName}", DataRead["T_WebName"].ToString());
            }
            DataRead.Close();
            DataRead.Dispose();

            //生成菜单
            strHtml.Replace("{#MenuMes}", GetWebMenu(nowClassID).ToString());
            return strHtml;
        }
        /// <summary>
        /// 生成网站菜单
        /// </summary>
        /// <param name="nowClassID"></param>
        /// <returns></returns>
        public static StringBuilder GetWebMenu(string nowClassID)
        { 
            //生成菜单
            OleDbDataReader DataRead = BLL.NoteInfo.GetNoteClassName();
            string strLeave = BLL.NoteInfo.GetClassLeave(nowClassID);
            nowClassID = (string.IsNullOrEmpty(strLeave) && (nowClassID != "about") && (nowClassID != "leave") && (nowClassID != "TMes")) ? "" : nowClassID;
            StringBuilder Temp = new StringBuilder();
            if (DataRead.HasRows)
            {
                Temp.Append("<li><a title=\"首页\" href=\"../Index.html\"" + ((string.IsNullOrEmpty(nowClassID)) ? " class=\"current\"" : "") + "><span></span>首页</a></li>");
                while (DataRead.Read())
                {
                    Temp.Append("<li><a title=\"" + DataRead["T_ClassName"].ToString() + "\" href=\"../" + DataRead["T_ClassEnName"].ToString() + "/Index.html\"" + GetCurrent(strLeave, DataRead["T_NoteClassID"].ToString()) + "><span></span>" + DataRead["T_ClassName"].ToString() + "</a></li>");
                }
                Temp.Append("<li><a title=\"个人简介\"  href=\"../About.html\"" + ((nowClassID == "about") ? " class=\"current\"" : "") + "><span></span>个人简介</a></li>");
                Temp.Append("<li><a title=\"对话\"  href=\"../LeaveMes.aspx\"" + ((nowClassID == "leave") ? " class=\"current\"" : "") + "><span></span>对话</a></li>"); 
                //Temp.Append("<li><a title=\"微博\"  href=\"../TMes.aspx\"" + ((nowClassID == "TMes") ? " class=\"current\"" : "") + "><span></span>微博</a></li>");
            }
            DataRead.Close();
            DataRead.Dispose();
            return Temp;
        }

        /// <summary>
        /// 生成选中菜单
        /// </summary>
        /// <param name="strLeave"></param>
        /// <param name="strNCID"></param>
        /// <returns></returns>
        private static string GetCurrent(string strLeave, string strNCID)
        {
            if (strLeave.IndexOf(",") > 0)
            {
                string[] strTemp = strLeave.Split(',');
                for (int i = 0; i < strTemp.Length; i++)
                {
                    if (strTemp[i] == strNCID)
                    {
                        return " class=\"current\" ";
                    }
                }
            }
            else
            {
                if (strLeave == strNCID)
                {
                    return " class=\"current\" ";
                }
            }
            return "";
        }
        /// <summary>
        /// 替换生成页面底部
        /// </summary>
        /// <param name="strKey"></param>
        /// <param name="dsData"></param>
        /// <returns></returns>
        public static StringBuilder HtmlReplaceFoot(System.Web.UI.Page rPage)
        {
            StringBuilder strHtml = GetBaseHtmlNote("foot", "", rPage);
            OleDbDataReader DataRead = BLL.WebInfo.GetWebBaseInfo("2");
            if (DataRead.HasRows)
            {
                DataRead.Read();
                strHtml.Replace("{#WebFootMes}", DataRead["T_WebLink"].ToString() + "&nbsp;<img src=\"../Images/IBCMes.gif\"/>&nbsp;" + DataRead["T_WebNumber"].ToString() + "&nbsp;" + rPage.Server.HtmlDecode(DataRead["T_SPSSMes"].ToString()));
            }
            DataRead.Close();
            DataRead.Dispose();
            return strHtml;
        }
        /// <summary>
        /// 生成列表
        /// </summary>
        /// <param name="rPage"></param>
        /// <param name="strClassID"></param>
        /// <param name="pageCount"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public static StringBuilder HtmlReplaceList(System.Web.UI.Page rPage, string strClassID, out int pageCount, out int recordCount,int pageSize,bool strType)
        {
            StringBuilder strHtml = new StringBuilder();
            DataTable DataRead = null;
            pageCount = 1;
            recordCount = 0;
            string strWhere = " WHERE N.T_NoteClassID<>'' ";
            string strOrderBy = (!strType) ? " T_NoteID DESC,T_NoteFlag desc " : " T_NoteFlag DESC,T_NoteID desc ";
            if (!string.IsNullOrEmpty(strClassID))
            {
                strWhere += string.Format(" and N.T_NoteClassID IN ('{0}') ", BLL.NoteInfo.GetNoteClassIDMes(strClassID).Replace(",","','"));
            }
            DataRead = BLL.NoteInfo.HtmlGetAllNoteInfo(pageSize, Convert.ToInt32(Common.GetMes.GetConfigAppValue("PageSize")), out pageCount, out recordCount, strWhere, strOrderBy);
            if (DataRead.Rows.Count > 0)
            {
                GetHtmlList(strHtml, DataRead, rPage);
            }
            return strHtml;
        }

        /// <summary>
        /// 生成不带样式的数据列表
        /// </summary>
        /// <param name="strHtml"></param>
        /// <param name="DataRead"></param>
        /// <param name="rPage"></param>
        /// <returns></returns>
        private static StringBuilder GetHtmlListNoStyle(StringBuilder strHtml, DataTable DataRead, System.Web.UI.Page rPage)
        {
            for (int i = 0; i < DataRead.Rows.Count; i++)
            {
                strHtml.Append("<div class=\"NoteTitle\">");
                strHtml.Append((DataRead.Rows[i]["T_NoteFlag"].ToString() == "1") ? "<span class=\"topTitle\">[推荐] </span>" : "");
                strHtml.Append("<a  title=\"" + DataRead.Rows[i]["T_NoteTitle"].ToString() + "\"  href=\"../" + DataRead.Rows[i]["T_ClassEnName"].ToString() + "/" + DataRead.Rows[i]["T_NoteID"].ToString() + ".html\">");
                strHtml.Append(DataRead.Rows[i]["T_NoteTitle"].ToString() + "</a></div><div class=\"NoteMes\">");
                strHtml.Append((DataRead.Rows[i]["T_NoteImage"].ToString() != "noImage.gif") ? "<a  title=\"" + DataRead.Rows[i]["T_NoteTitle"].ToString() + "\"  href=\"../" + DataRead.Rows[i]["T_ClassEnName"].ToString() + "/" + DataRead.Rows[i]["T_NoteID"].ToString() + ".html\"><img src=\"../UpLoad/Images/Small/" + DataRead.Rows[i]["T_NoteImage"].ToString() + "\" class=\"TopImage\" /></a>" : "");
                strHtml.Append(Common.GetMes.GetFirstString(DataRead.Rows[i]["T_NoteDes"].ToString(), 200) + "..<div class=\"OtherMes\">");
                strHtml.Append(Convert.ToDateTime(DataRead.Rows[i]["T_DateTime"].ToString()).ToString("yyyy年MM月dd日") + "&nbsp;[<a  target=\"_blank\" href=\"../" + DataRead.Rows[i]["T_ClassEnName"].ToString() + "/Index.html\" title=\"" + DataRead.Rows[i]["T_ClassName"].ToString() + "\">" + DataRead.Rows[i]["T_ClassName"].ToString() + "</a>]&nbsp;浏览:" + DataRead.Rows[i]["T_BrowerCount"].ToString() + "次&nbsp;评论:" + BLL.LeaveInfo.GetLeaveCount(DataRead.Rows[i]["T_NoteID"].ToString()) + "条&nbsp;Tags:" + TagsKeyCommon(DataRead.Rows[i]["T_NoteKey"].ToString(), rPage) + "</div></div>");
            }
            return strHtml;
        }
        /// <summary>
        /// 生成数据列表
        /// </summary>
        /// <param name="strHtml"></param>
        /// <param name="DataRead"></param>
        /// <returns></returns>
        private static StringBuilder GetHtmlList(StringBuilder strHtml, DataTable DataRead, System.Web.UI.Page rPage)
        {
            for (int i = 0; i < DataRead.Rows.Count; i++)
            {
                strHtml.Append("<div class=\"NoteTitle\">");
                strHtml.Append((DataRead.Rows[i]["T_NoteFlag"].ToString() == "1") ? "<span class=\"topTitle\">[推荐] </span>" : "");
                strHtml.Append("<a  title=\"" + DataRead.Rows[i]["T_NoteTitle"].ToString() + "\"  href=\"../" + DataRead.Rows[i]["T_ClassEnName"].ToString() + "/" + DataRead.Rows[i]["T_NoteID"].ToString() + ".html\">");
                strHtml.Append(DataRead.Rows[i]["T_NoteTitle"].ToString() + "</a></div><div class=\"NoteMes\">");
                strHtml.Append((DataRead.Rows[i]["T_NoteImage"].ToString() != "noImage.gif") ? "<a  title=\"" + DataRead.Rows[i]["T_NoteTitle"].ToString() + "\"  href=\"../" + DataRead.Rows[i]["T_ClassEnName"].ToString() + "/" + DataRead.Rows[i]["T_NoteID"].ToString() + ".html\"><img src=\"../UpLoad/Images/Small/" + DataRead.Rows[i]["T_NoteImage"].ToString() + "\" class=\"TopImage\" /></a>" : "");
                strHtml.Append(Common.GetMes.GetFirstString(DataRead.Rows[i]["T_NoteDes"].ToString(), 200) + "..<div class=\"OtherMes\">");
                strHtml.Append(Convert.ToDateTime(DataRead.Rows[i]["T_DateTime"].ToString()).ToString("yyyy年MM月dd日") + "&nbsp;[<a  target=\"_blank\" href=\"../" + DataRead.Rows[i]["T_ClassEnName"].ToString() + "/Index.html\" title=\"" + DataRead.Rows[i]["T_ClassName"].ToString() + "\">" + DataRead.Rows[i]["T_ClassName"].ToString() + "</a>]&nbsp;浏览:" + DataRead.Rows[i]["T_BrowerCount"].ToString() + "次&nbsp;评论:" + BLL.LeaveInfo.GetLeaveCount(DataRead.Rows[i]["T_NoteID"].ToString()) + "条&nbsp;Tags:" + TagsKeyCommon(DataRead.Rows[i]["T_NoteKey"].ToString(), rPage) + "</div></div>");
            }
            return strHtml;
        }
        /// <summary>
        /// 生成分页导航
        /// </summary>
        /// <param name="pageCount"></param>
        /// <param name="recordCount"></param>
        /// <param name="nowPage"></param>
        /// <returns></returns>
        public static StringBuilder GetPageMes(int pageCount,int recordCount,int nowPage)
        {
            StringBuilder strHtml = new StringBuilder("<span style=\"color:#666666;\">[" + recordCount + "]条/共[" + pageCount + "]页 </span>");
            strHtml.Append((nowPage == 1) ? "<span class=\"disabled\">首页</span>" : "<a href=\"Index.html\">首页</a>");
            strHtml.Append((nowPage > 1) ? "<a href=\"Index"+((nowPage==2)?"":"_"+(nowPage-1))+".html\">上一页</a>" : "<span class=\"disabled\">上一页</span>");
            int startIndex = 1;
            if (nowPage > 5 && pageCount > 10)
            {
                startIndex = (pageCount > (nowPage + 5)) ? (nowPage - 4) : ((nowPage - 4) - ((nowPage + 5) - pageCount));
            }
            for (int i = startIndex; i <= ((pageCount < 10) ? pageCount : (startIndex+9)); i++)
            {
                strHtml.Append((nowPage == i) ? "<span class=\"current\">" + i + "</span>" : ("<a href=Index" + (((i == 1) ? "" : ("_" + i)) + ".html >" + i + "</a>")));
            }
            strHtml.Append((nowPage < pageCount) ? "<a href=\"Index_" + (nowPage + 1) + ".html\">下一页</a>" : "<span class=\"disabled\">下一页</span>");
            strHtml.Append((nowPage == pageCount) ? "<span class=\"disabled\">尾页</span>" : "<a href=\"Index_"+pageCount+".html\">尾页</a>");
            return strHtml;
        }

        /// <summary>
        /// 生成Tags关键字链接
        /// </summary>
        /// <param name="strTags"></param>
        /// <param name="rPage"></param>
        /// <returns></returns>
        public static string TagsKeyCommon(string strTags, System.Web.UI.Page rPage)
        {
            string strCommonKey = string.Empty;
            if (strTags.IndexOf(",") > 0)
            {
                string[] strKey = strTags.Split(',');
                for (int i = 0; i < strKey.Length; i++)
                {
                    strCommonKey += ((i == 0) ? "" : ",") + "<a title=\"" + strKey[i] + "\"  href=\"../Search.aspx?keys=" + rPage.Server.UrlEncode(strKey[i]) + "\"  target=\"_blank\">" + strKey[i] + "</a>";
                }
            }
            else
            {
                strCommonKey = "<a title=\"" + strTags + "\"  href=\"../Search.aspx?keys=" + rPage.Server.UrlEncode(strTags) + "\"  target=\"_blank\">" + strTags + "</a>";
            }
            return strCommonKey;
        }

        /// <summary>
        /// 生成友情链接
        /// </summary>
        /// <returns></returns>
        public static StringBuilder HtmlReplaceLink()
        {
            StringBuilder strHtml = new StringBuilder();
            OleDbDataReader DataRead = BLL.LinkInfo.GetLinkMes("");
            if (DataRead.HasRows)
            {
                while (DataRead.Read())
                {
                    strHtml.Append("<a title=\"" + DataRead["T_LinkTitle"].ToString() + "\"  target=\"_blank\" href=\"" + DataRead["T_LinkUrl"].ToString() + "\">" + DataRead["T_LinkTitle"].ToString() + "</a>&nbsp;");
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            return strHtml;
        }

        /// <summary>
        /// 返回全文搜索Html
        /// </summary>
        /// <returns></returns>
        public static StringBuilder HtmlSearch()
        {
            StringBuilder strHtml = new StringBuilder("<div class=\"NoteRight_Title research_title\"> 整站搜索 </div><div class=\"Right_Content\"><input type=\"text\" maxlength=\"15\" class=\"search\" id=\"searchKey\"/> <input type=\"button\" value=\"搜索\" id=\"NoteSearch\"/></div>");
            return strHtml;
        }

        /// <summary>
        /// 返回Top的内容信息
        /// </summary>
        /// <param name="Top"></param>
        /// <param name="Where"></param>
        /// <param name="Order"></param>
        /// <returns></returns>
        public static StringBuilder HtmlGetTopNote()
        {
            StringBuilder strHtml = new StringBuilder("<div class=\"NoteRight_Title news_title\">热点信息</div><div class=\"Right_Content\">");
            OleDbDataReader DataRead = BLL.NoteInfo.HtmlGetTopNoteInfo("10", " ", " ORDER BY T_BrowerCount desc ");
            if (DataRead.HasRows)
            {
                while (DataRead.Read())
                {
                    strHtml.Append("<a href=\"../" + DataRead["T_ClassEnName"].ToString() + "/" + DataRead["T_NoteID"].ToString() + ".html\" title=\"" + DataRead["T_NoteTitle"].ToString() + "\">");
                    strHtml.Append(Common.GetMes.GetFirstString(DataRead["T_NoteTitle"].ToString(), 32) + "..");
                    strHtml.Append("</a><br/>");
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            strHtml.Append("</div>");
            return strHtml;
        }
        /// <summary>
        /// 返回Top的最新内容信息
        /// </summary>
        /// <param name="Top"></param>
        /// <param name="Where"></param>
        /// <param name="Order"></param>
        /// <returns></returns>
        public static StringBuilder HtmlGetTopNewNote()
        {
            StringBuilder strHtml = new StringBuilder("<div class=\"NoteRight_Title newsletter_title\">最新日志</div><div class=\"Right_Content\">");
            OleDbDataReader DataRead = BLL.NoteInfo.HtmlGetTopNoteInfo("10", " ", " ORDER BY T_NoteID desc ");
            if (DataRead.HasRows)
            {
                while (DataRead.Read())
                {
                    strHtml.Append("<a href=\"../" + DataRead["T_ClassEnName"].ToString() + "/" + DataRead["T_NoteID"].ToString() + ".html\" title=\"" + DataRead["T_NoteTitle"].ToString() + "\">");
                    strHtml.Append(Common.GetMes.GetFirstString(DataRead["T_NoteTitle"].ToString(), 32) + "..");
                    strHtml.Append("</a><br/>");
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            strHtml.Append("</div>");
            return strHtml;
        }

        /// <summary>
        /// 返回随机整数 用于获取随机数据
        /// </summary>
        /// <returns></returns>
        private static int GetRandom()
        {
            Random rnd = new Random(unchecked((int)DateTime.Now.Ticks));
            return rnd.Next();
        }

        /// <summary>
        /// 返回Top的随即内容信息
        /// </summary>
        /// <param name="Top"></param>
        /// <param name="Where"></param>
        /// <param name="Order"></param>
        /// <returns></returns>
        public static StringBuilder HtmlGetTopRndNote()
        {
            StringBuilder strHtml = new StringBuilder("<div class=\"NoteRight_Title news_title\">随便看看</div><div class=\"Right_Content\">");
            OleDbDataReader DataRead = BLL.NoteInfo.HtmlGetTopNoteInfo("10", " ", " ORDER BY rnd("+(-1*GetRandom())+"*T_NoteID) ");
            if (DataRead.HasRows)
            {
                while (DataRead.Read())
                {
                    strHtml.Append("<a href=\"../" + DataRead["T_ClassEnName"].ToString() + "/" + DataRead["T_NoteID"].ToString() + ".html\" title=\"" + DataRead["T_NoteTitle"].ToString() + "\">");
                    strHtml.Append(Common.GetMes.GetFirstString(DataRead["T_NoteTitle"].ToString(), 32) + "..");
                    strHtml.Append("</a><br/>");
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            strHtml.Append("</div>");
            return strHtml;
        }
        /// <summary>
        /// 生成信息分类
        /// </summary>
        /// <returns></returns>
        public static StringBuilder HtmlGetClassMes()
        {
            StringBuilder strHtml = new StringBuilder("<div class=\"NoteRight_Title testimonial_title\">信息分类</div><div class=\"Right_Content\">");
            OleDbDataReader DataRead = BLL.NoteInfo.GetNoteClassName();
            if (DataRead.HasRows)
            {
                DataTable dtClass = new DataTable();
                while (DataRead.Read())
                {
                    strHtml.Append("<a  title=\"" + DataRead["T_ClassName"].ToString() + "\"  href=../" + DataRead["T_ClassEnName"].ToString() + "/Index.html style=\"font-size: 14px; color:#000000;\">" + DataRead["T_ClassName"].ToString() + "</a><br/>");
                    dtClass = BLL.NoteInfo.GetNoteClassHtmlMes(DataRead["T_NoteClassID"].ToString());
                    for (int i = 0; i < dtClass.Rows.Count; i++)
                    {
                        strHtml.Append("┗━<a   title=\"" + dtClass.Rows[i]["T_ClassName"].ToString() + "\"  href=../" + dtClass.Rows[i]["T_ClassEnName"].ToString() + "/Index.html>" + dtClass.Rows[i]["T_ClassName"].ToString() + " [" + BLL.NoteInfo.GetClassNoteCountMes(dtClass.Rows[i]["T_NoteClassID"].ToString()) + "] </a><br/>");
                    }
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            strHtml.Append("</div>");
            return strHtml;
        }
        /// <summary>
        /// 生成所有关键字
        /// </summary>
        /// <param name="Top"></param>
        /// <param name="rPage"></param>
        /// <returns></returns>
        public static StringBuilder HtmlGetHotKey(string Top, System.Web.UI.Page rPage)
        {
            StringBuilder strHtml = new StringBuilder("<div class=\"NoteRight_Title business_news_title\">Tags</div><div class=\"Right_Content\">");
            OleDbDataReader DataRead = BLL.NoteInfo.GetHotKey(Top);
            if (DataRead.HasRows)
            {
                while (DataRead.Read())
                {
                    string[] strKey = DataRead["T_NoteKey"].ToString().Split(',');
                    for (int i = 0; i < strKey.Length; i++)
                    {
                        strHtml.Append("<a  title=\"" + strKey[i] + "\" href=\"../Search.aspx?keys=" + rPage.Server.UrlEncode(strKey[i]) + "\"  target=\"_blank\">" + strKey[i] + "</a>&nbsp;");
                    }
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            strHtml.Append("</div>");
            return strHtml;
        }
        /// <summary>
        /// 返回个人简介信息
        /// </summary>
        /// <returns></returns>
        public static StringBuilder HtmlAboutMes()
        {
            StringBuilder strHtml = new StringBuilder();
            OleDbDataReader DataRead = BLL.WebInfo.GetWebBaseInfo("3");
            if (DataRead.HasRows)
            {
                DataRead.Read();
                strHtml.Append(DataRead["T_WebAbout"].ToString());
            }
            DataRead.Close();
            DataRead.Dispose();
            return strHtml;
        }
        /// <summary>
        /// 返回上一篇 下一篇信息
        /// </summary>
        /// <param name="strNID"></param>
        /// <returns></returns>
        public static StringBuilder HtmlNextUp(string strNID)
        {
            StringBuilder strHtml = new StringBuilder();
            OleDbDataReader DataRead = BLL.NoteInfo.GetNextUpMes(strNID, "next");
            if (DataRead.HasRows)
            {
                DataRead.Read();
                strHtml.Append("上一篇：<a href=\"../" + DataRead["T_ClassEnName"].ToString() + "/" + DataRead["T_NoteID"].ToString() + ".html\" title=\"" + DataRead["T_NoteTitle"].ToString() + "\">");
                strHtml.Append(Common.GetMes.GetFirstString(DataRead["T_NoteTitle"].ToString(), 35) + "</a>&nbsp;&nbsp;");
            }
            else
            {
                strHtml.Append("上一篇：<a href=\"../Index.html\" title=\"个人网站..\">返回首页</a>&nbsp;&nbsp;");
            }
            DataRead.Close();
            DataRead.Dispose();

            DataRead = BLL.NoteInfo.GetNextUpMes(strNID, "");
            if (DataRead.HasRows)
            {
                DataRead.Read();
                strHtml.Append("下一篇：<a href=\"../" + DataRead["T_ClassEnName"].ToString() + "/" + DataRead["T_NoteID"].ToString() + ".html\" title=\"" + DataRead["T_NoteTitle"].ToString() + "\">");
                strHtml.Append(Common.GetMes.GetFirstString(DataRead["T_NoteTitle"].ToString(), 35) + "</a>");
            }
            else
            {
                strHtml.Append("下一篇：<a href=\"../Index.html\" title=\"个人网站..\">返回首页</a>");
            }
            DataRead.Close();
            DataRead.Dispose();
            return strHtml;
        }
        /// <summary>
        /// 返回最新微博信息
        /// </summary>
        /// <param name="Top"></param>
        /// <returns></returns>
        public static string GetTopTMes(string Top)
        {
            Top = (string.IsNullOrEmpty(Top)) ? "10" : Top;
            StringBuilder strHtml = new StringBuilder("<div class=\"NoteRight_Title business_news_title\">最新微博</div><div class=\"Right_Content\"><a href=\"../TMes.aspx\">");
            OleDbDataReader DataRead = BLL.NoteInfo.GetTopTMes(Top);
            if (DataRead.HasRows)
            {
                while (DataRead.Read())
                {
                    strHtml.Append(Common.GetMes.GetFirstString(DataRead["T_NoteDes"].ToString(),33)+"<br/>");
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            strHtml.Append("</a></div>");
            return strHtml.ToString();
        }

        /// <summary>
        /// 获取Note列表
        /// </summary>
        /// <param name="iTopCount"></param>
        /// <param name="noteClassEnName"></param>
        /// <returns></returns>
        public static string GetNote(int iTopCount ,string noteClassEnName,int iDisType)
        {
            if (iDisType<=0)
            {
                iDisType = 0;
            }
            var sb = new StringBuilder();

            var dr = BLL.NoteInfo.GetNoteInfoByEnName(iTopCount,"", noteClassEnName);

            if (dr.HasRows)
            {
                switch (iDisType)
                {
                    case 0://不带样式
                        while (dr.Read())
                        {
                            sb.Append("<a target=\"_blank\" href=\"../" + noteClassEnName + "/" + dr["T_NoteID"].ToString() +
                            ".html\" title=\"" + dr["T_NoteTitle"].ToString() + "\">");
                            sb.Append(dr["T_NoteTitle"].ToString() + "</a><br/>");
                        }
                        break;
                    case 1://带时间（内容居左，时间居右）
                        while (dr.Read())
                        {
                            var dt = Convert.ToDateTime(dr["T_DateTime"].ToString());

                            sb.Append("<span><div style=\"float:left;\"><a target=\"_blank\" href=\"../" + noteClassEnName + "/" + dr["T_NoteID"].ToString() +
                            ".html\" title=\"" + dr["T_NoteTitle"].ToString() + "\">");
                            sb.Append(dr["T_NoteTitle"].ToString() + "</a></div>");
                            sb.Append("<div style=\"float:right;\">" + dt.ToString("yyyy-MM-dd") + "</div></span><br/>");
                        }
                        break;
                    case 2://只查询图片
                        while (dr.Read())
                        {

                            sb.Append("<a target=\"_blank\" href=\"../" + noteClassEnName + "/" + dr["T_NoteID"].ToString() +
                            ".html\" title=\"" + dr["T_NoteTitle"].ToString() + "\">");
                            sb.Append("<img src=\"../UpLoad/Images/" + dr["T_NoteImage"].ToString() + "\" border=\"0\" alt=\"" + dr["T_NoteTitle"].ToString() + "\" />");
                            sb.Append("</a>&nbsp;");

                            //<img src="img/005.jpg" border="0" width="91" height="119" alt="谭戈">

                        }
                        break;
                }
                
            }
            dr.Close();
            dr.Dispose();

            return sb.ToString();

        }

        public static string GetHotNote()
        {
            var sb = new StringBuilder();

            var dr = BLL.NoteInfo.GetNoteInfoByEnName(10, "", "");

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    sb.Append("<span ><font style=\"FONT-SIZE: 12px; COLOR: #333333; FONT-FAMILY: Webdings\">4</font>");
                    sb.Append("<a target=\"_blank\" href=\"../" + dr["t_classenname"].ToString() + "/" + dr["T_NoteID"].ToString() + ".html\">");
                    sb.Append(dr["T_NoteTitle"].ToString().Length > 21 ? dr["T_NoteTitle"].ToString().Substring(0, 21) + "…" : dr["T_NoteTitle"].ToString());
                    sb.Append("</a></span><br/>");
                }

            }
            dr.Close();
            dr.Dispose();

            return sb.ToString();

        }

        /// <summary>
        /// 生成网站地图
        /// </summary>
        /// <returns></returns>
        public static string GenSiteMap()
        {
            var dtClass = new DataTable();//note_class
            var dtNoteList = new DataTable();//note_info
            var sb = new StringBuilder();//html
            var webSite = "http://" + Common.GetMes.GetConfigAppValue("WebSite");

            dtClass = BLL.NoteInfo.GetNoteClassAllCols();
            sb.Append("<pre>");
            //遍历class)
            for (int i = 0; i < dtClass.Rows.Count; i++)
            {
                sb.Append("<a href=\"" + webSite + "/" + dtClass.Rows[i]["T_ClassEnName"] + "/Index.html\" TARGET=_blank>" + dtClass.Rows[i]["T_ClassName"] + "</a><br/>");
                var classid = dtClass.Rows[i]["T_NoteClassID"].ToString();
                
                //遍历note(取100行数据)
                dtNoteList = BLL.NoteInfo.GetNoteInfoByClassId(classid, "100");
                
                for (int j = 0; j < dtNoteList.Rows.Count; j++)
                {
                    if (!string.IsNullOrEmpty(dtNoteList.Rows[j]["Remark"].ToString()))//如果不为空则已生成页面，则生成地图
                    {
                        sb.Append("&nbsp;&nbsp;<a href=\"" + webSite + "/" + dtClass.Rows[i]["T_ClassEnName"] + "/" + dtNoteList.Rows[j]["T_NoteID"] + ".html\" TARGET=_blank>" + dtNoteList.Rows[j]["T_NoteTitle"] + "</a><br />");
                    }
                }
            }

            sb.Append("</pre>");

            return sb.ToString();

        }

    }
}
